home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
util
/
Events.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
2KB
|
81 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from primitives import Delegate
from logging import getLogger
log = getLogger('events')
class BadEventException(Exception):
pass
class EventMixin(object):
events = set()
def __init__(self):
if not hasattr(self, 'handlers'):
self.handlers = { }
self.clear()
def bind(self, ename, callback):
self.handlers[ename] += callback
bind_event = bind
def event(self, ename, *args):
if ename not in self.events:
raise BadEventException(type(self).__name__, ename, self.events)
if self.handlers[ename]:
self.handlers[ename](*args)
def unbind(self, ename, callback):
if self.handlers[ename]:
try:
self.handlers[ename] -= callback
except ValueError:
pass
except:
None<EXCEPTION MATCH>ValueError
None<EXCEPTION MATCH>ValueError
def clear(self):
for evtname in self.events:
self.handlers[evtname] = Delegate()
def __getattr__(self, attr):
if attr in self.events:
return self.handlers[attr]
else:
return object.__getattribute__(self, attr)
def event(f):
import functools as functools
def wrapper(self, *a):
name = f.func_name
retval = f(self, *a)
if isinstance(retval, tuple):
self.event(name, *retval)
elif retval not in (None, sentinel):
self.event(name, retval)
elif retval is None:
self.event(name, *a)
wrapper = (functools.wraps(f),)(wrapper)
return wrapper